import axios from 'axios'
import { DownloadApi, setUploadApi, UploadApi } from '@zl-crud/common'

const baseUrl = '/api/storage'

// 配置上传的接口实现
const uploadApi: UploadApi = {
  // 获取分片信息
  sharding: (data: any) => axios.post(baseUrl + '/upload/sharding', data),
  // 上传初始化
  init: (data: any) => axios.post(baseUrl + '/upload/init', data),
  // 合并文件
  complete: (fileKey: string, data: any) => axios.post(baseUrl + '/upload/complete/' + fileKey, data),
}
// 设置全局上传下载接口实现
// setUploadApi(uploadApi)

// 配置下载的接口实现
const downloadApi: DownloadApi = {
  // 获取文件详情
  getFile: (fileKey: string[]) => axios.get('/api/getFile?fileKey=' + fileKey),
  // 下载文件
  download: (fileKey: any) => axios.get(baseUrl + '/download/' + fileKey),
}
